home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 3: Developer Tools / Linux Cubed Series 3 - Developer Tools.iso / devel / db / esm-3.1 / esm-3 / usr / local / sm / tests / misc / indexloadscan.c < prev    next >
Encoding:
C/C++ Source or Header  |  1996-05-05  |  7.4 KB  |  370 lines

  1. /*
  2.  * $RCSfile: indexloadscan.c,v $
  3.  * $Revision: 1.1.1.1 $
  4.  * $Date: 1996/05/04 21:56:07 $
  5.  */
  6. #include "sm_client.h"
  7. #include <stdlib.h>
  8.  
  9. #include <strings.h>
  10. #include <sys/file.h>
  11. #include <sys/time.h>
  12. #include <sys/resource.h>
  13. #ifdef __cplusplus
  14. #    include <osfcn.h>
  15. #else
  16.     extern char        *malloc();
  17.     extern char        *getenv();
  18. #endif
  19.  
  20. TID tid;
  21. int bufGroup;
  22. VOLID volid;
  23.  
  24. int testIntIndex(int keyCount);
  25. int testDoubleIndex(int keyCount);
  26.  
  27. /*
  28.  * ErrorCheck( ) is a simple routine for checking
  29.  * Storage Manager return codes.
  30.  */
  31.  int
  32. ErrorCheck (
  33.     int    e,              /* error return code */
  34.     char   *routine        /* the routine that caused an error */
  35. )
  36. {
  37.     if (e < 0) {
  38.         fprintf(stderr, "Got a Storage Manager error from %s\n", routine);
  39.         fprintf(stderr, "Error = %s\n", sm_Error(sm_errno));
  40.         exit(1);
  41.     }
  42.     return(0);
  43. }
  44.  
  45.  
  46. main (int argc, char** argv)
  47. {
  48.     int e;
  49.     char    *errorMsg;
  50.  
  51.     /*
  52.      *  Read the default configuration files to
  53.      *  have the bufpages option set.
  54.      */
  55.     e = sm_ReadConfigFile(NULL, argv[0], &errorMsg);
  56.     if (e != esmNOERROR) {
  57.         fprintf(stderr, "Configuration file error: %s\n", errorMsg);
  58.         ErrorCheck(e, "sm_ReadConfigFile");
  59.         exit(0);
  60.     }
  61.  
  62.     /*
  63.      *  Set any options from the command line
  64.      */
  65.     e = sm_ParseCommandLine(&argc, argv, &errorMsg);
  66.     if (e != esmNOERROR) {
  67.         fprintf(stderr, "command line error: %s\n", errorMsg);
  68.         ErrorCheck(e, "sm_PargeCommandLine");
  69.         exit(0);
  70.     }
  71.     
  72.     /* check for the proper number of arguments */
  73.     if (argc != 2) {
  74.         fprintf(stderr,"usage: %s keycount\n", argv[0]);
  75.         exit(-1);
  76.     }
  77.  
  78.     /*
  79.      *    get the parameters of the test
  80.      */
  81.     int keyCount = atoi(argv[1]);
  82.  
  83.     /*
  84.      * Initialize the storage manager.
  85.      */
  86.     e = sm_Initialize();
  87.     ErrorCheck(e, "sm_Initialize");
  88.  
  89.     /*
  90.      *    get the disk volume id
  91.      */
  92.     char* volidStr = getenv("EVOLID");
  93.     if (volidStr == NULL) {
  94.         printf("Please set the EVOLID environment variable\n");
  95.         exit(1);
  96.     }
  97.     volid = atoi(volidStr);
  98.  
  99.     /*
  100.      * Open a small buffer group.
  101.      */
  102.     printf("Open a buffer group\n");
  103.     e = sm_OpenBufferGroup(100, BF_LRU, &bufGroup, NOFLAGS);
  104.     ErrorCheck(e, "sm_OpenBufferGroup");
  105.  
  106.  
  107.     testIntIndex(keyCount);
  108.     testDoubleIndex(keyCount);
  109.  
  110.     printf("Finished\n");
  111.  
  112.  
  113.     /*
  114.      * Shut everything down.
  115.      */
  116.     e = sm_CloseBufferGroup(bufGroup);
  117.     ErrorCheck(e, "sm_CloseBufferGroup");
  118.  
  119.  
  120.     e = sm_ShutDown();
  121.     ErrorCheck(e, "sm_ShutDown");
  122.  
  123.     exit(0);
  124. }
  125.  
  126.  
  127. int testIntIndex(int keyCount)
  128. {
  129.     int e;
  130.  
  131.     /*
  132.      *    start the transation
  133.      */
  134.     printf("Start a transaction\n");
  135.     e = sm_BeginTransaction( &tid );
  136.     ErrorCheck(e, "sm_BeginTransaction");
  137.  
  138.     /*
  139.      * Create Index object
  140.      */
  141.     printf("creating index object\n");
  142.     IID ndx;
  143.     e = sm_CreateIndex(volid, bufGroup, SM_BTREENDX, SM_int,
  144.                                     sizeof(int), sizeof(OID), TRUE, &ndx);
  145.     ErrorCheck(e, "sm_CreateIndex"); 
  146.  
  147.  
  148.     int buff;
  149.     KEY key;
  150.     key.length = sizeof(buff);
  151.     key.valuePtr = &buff;
  152.     OID    oid;
  153.     bzero((char *)&oid, (int)sizeof(oid));
  154.  
  155.     printf("Insert %d integer keys into a unique index\n", keyCount);
  156.     for (int i = 0; i < keyCount; i++)   {
  157.         buff = i;
  158.  
  159.         e = sm_InsertEntry(&ndx, bufGroup, &key, &oid);
  160.         ErrorCheck(e, "sm_InsertEntry");
  161.         }
  162.  
  163.     /*
  164.      *    Commit the transaction
  165.      */
  166.     e = sm_CommitTransaction(tid);
  167.     ErrorCheck(e, "sm_CommitTransaction");
  168.  
  169.     printf("Finished\n");
  170.  
  171.  
  172.     /*
  173.      *  start the transation
  174.      */
  175.     printf("Start a new transaction\n");
  176.     e = sm_BeginTransaction( &tid );
  177.     ErrorCheck(e, "sm_BeginTransaction");
  178.  
  179.     printf("Looking up everything inserted so far (serial) \n");
  180.     buff = 0;
  181.     key.length = sizeof(buff);
  182.     key.valuePtr = &buff;
  183.     KEY keyEnd;
  184.     keyEnd.length = sizeof(buff);
  185.     keyEnd.valuePtr = &keyCount;
  186.     SMCURSOR cursor;
  187.     e = sm_FetchInit(&ndx, bufGroup, &key, SM_EQ, &keyEnd, SM_LEQ, &cursor);
  188.     ErrorCheck(e, "sm_FetchInit");
  189.     for (i = 0; i < keyCount; i++)  {
  190.         int e;
  191.         BOOL eof;
  192.  
  193.         e = sm_FetchNext(&cursor, &key, &oid, &eof);
  194.         ErrorCheck(e, "sm_FetchNext");
  195.         if (eof)  {
  196.             printf("unexpected EOF\n");
  197.             exit(-1);
  198.             }
  199.         if (buff != i)  {
  200.             printf("index inconsistent\n");
  201.             exit(-1);
  202.             }
  203.         }
  204.     printf("Successful.\n");
  205.  
  206.  
  207.     /*
  208.      *  Commit the transaction
  209.      */
  210.     printf("Commit the transaction\n");
  211.     e = sm_CommitTransaction(tid);
  212.     ErrorCheck(e, "sm_CommitTransaction");
  213.     
  214.  
  215.     /*
  216.      *  start the transation
  217.      */
  218.     printf("Start a new transaction\n");
  219.     e = sm_BeginTransaction( &tid );
  220.     ErrorCheck(e, "sm_BeginTransaction");
  221.  
  222.     printf("Remove everything inserted so far (serial) \n");
  223.     key.length = sizeof(buff);
  224.     key.valuePtr = &buff;
  225.     for (i = 0; i < keyCount; i++)  {
  226.  
  227.         buff = i;
  228.  
  229.         e = sm_RemoveEntry(&ndx, bufGroup, &key, &oid);
  230.         ErrorCheck(e, "sm_RemoveEntry");
  231.         }
  232.  
  233.     e = sm_DestroyIndex(&ndx, bufGroup);
  234.     ErrorCheck(e, "sm_DestroyIndex"); 
  235.  
  236.     /*
  237.      *  Commit the transaction
  238.      */
  239.     printf("Commit the transaction\n");
  240.     e = sm_CommitTransaction(tid);
  241.     ErrorCheck(e, "sm_CommitTransaction");
  242.     
  243.     printf("Successful.\n");
  244.     return(0);
  245. }
  246.  
  247.  
  248. int testDoubleIndex(int keyCount)
  249. {
  250.     int e;
  251.  
  252.     /*
  253.      *    start the transation
  254.      */
  255.     printf("Start a transaction\n");
  256.     e = sm_BeginTransaction( &tid );
  257.     ErrorCheck(e, "sm_BeginTransaction");
  258.  
  259.     /*
  260.      * Create Index object
  261.      */
  262.     printf("creating index object\n");
  263.     IID ndx;
  264.     e = sm_CreateIndex(volid, bufGroup, SM_BTREENDX, SM_double,
  265.                                     sizeof(double), sizeof(OID), TRUE, &ndx);
  266.     ErrorCheck(e, "sm_CreateIndex"); 
  267.  
  268.  
  269.     double buff;
  270.     KEY key;
  271.     key.length = sizeof(buff);
  272.     key.valuePtr = &buff;
  273.     OID    oid;
  274.     bzero((char *)&oid, (int)sizeof(oid));
  275.  
  276.     printf("Insert %d double keys into a unique index\n", keyCount);
  277.     for (int i = 0; i < keyCount; i++)   {
  278.         buff = i;
  279.  
  280.         e = sm_InsertEntry(&ndx, bufGroup, &key, &oid);
  281.         ErrorCheck(e, "sm_InsertEntry");
  282.         }
  283.  
  284.     /*
  285.      *    Commit the transaction
  286.      */
  287.     e = sm_CommitTransaction(tid);
  288.     ErrorCheck(e, "sm_CommitTransaction");
  289.  
  290.     printf("Finished\n");
  291.  
  292.  
  293.     /*
  294.      *  start the transation
  295.      */
  296.     printf("Start a new transaction\n");
  297.     e = sm_BeginTransaction( &tid );
  298.     ErrorCheck(e, "sm_BeginTransaction");
  299.  
  300.     printf("Looking up everything inserted so far (serial) \n");
  301.     buff = 0;
  302.     double buffEnd = keyCount;
  303.     key.length = sizeof(buff);
  304.     key.valuePtr = &buff;
  305.     KEY keyEnd;
  306.     keyEnd.length = sizeof(buffEnd);
  307.     keyEnd.valuePtr = &buffEnd;
  308.     SMCURSOR cursor;
  309.     e = sm_FetchInit(&ndx, bufGroup, &key, SM_EQ, &keyEnd, SM_LEQ, &cursor);
  310.     ErrorCheck(e, "sm_FetchInit");
  311.     for (i = 0; i < keyCount; i++)  {
  312.         int e;
  313.         BOOL eof;
  314.  
  315.         e = sm_FetchNext(&cursor, &key, &oid, &eof);
  316.         ErrorCheck(e, "sm_FetchNext");
  317.         if (eof)  {
  318.             printf("unexpected EOF\n");
  319.             exit(-1);
  320.             }
  321.         if (buff != i)  {
  322.             printf("index inconsistent\n");
  323.             exit(-1);
  324.             }
  325.         }
  326.     printf("Successful.\n");
  327.  
  328.  
  329.     /*
  330.      *  Commit the transaction
  331.      */
  332.     printf("Commit the transaction\n");
  333.     e = sm_CommitTransaction(tid);
  334.     ErrorCheck(e, "sm_CommitTransaction");
  335.     
  336.  
  337.     /*
  338.      *  start the transation
  339.      */
  340.     printf("Start a new transaction\n");
  341.     e = sm_BeginTransaction( &tid );
  342.     ErrorCheck(e, "sm_BeginTransaction");
  343.  
  344.     printf("Remove everything inserted so far (serial) \n");
  345.     key.length = sizeof(buff);
  346.     key.valuePtr = &buff;
  347.     for (i = 0; i < keyCount; i++)  {
  348.  
  349.         buff = i;
  350.  
  351.         e = sm_RemoveEntry(&ndx, bufGroup, &key, &oid);
  352.         ErrorCheck(e, "sm_RemoveEntry");
  353.         }
  354.  
  355.     e = sm_DestroyIndex(&ndx, bufGroup);
  356.     ErrorCheck(e, "sm_DestroyIndex"); 
  357.  
  358.     /*
  359.      *  Commit the transaction
  360.      */
  361.     printf("Commit the transaction\n");
  362.     e = sm_CommitTransaction(tid);
  363.     ErrorCheck(e, "sm_CommitTransaction");
  364.     
  365.     printf("Successful.\n");
  366.     return(0);
  367. }
  368.  
  369.     
  370.